<template>
	<view>
		<form @submit="SubmitUserName">
			<view class="userName">
				<input  v-model="name" placeholder="账号名/邮箱/手机号" type="text">
				<view class="hr-class"></view>
			</view>
			<view class="userPassword">
				<input   v-model="pass" placeholder="请输入密码" type="text">
				<view class="hr-class"></view>
			</view>
			<button form-type="submit">登录</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				pass: ''
			}
		},
		methods: {
			SubmitUserName: function(e) {
				var formdata = JSON.stringify(e.detail.value)
				let thiw = this;
				console.log('form发生了submit事件，携带数据为：' + formdata)
				uni.request({
					url:"/static/userJson/user.json",
					data:{
						name:thiw.name,
						pass:thiw.pass
					},
					success:res=>{
						for (let var1 in res.data) {
							if(this.name==res.data[var1].user && this.pass==res.data[var1].pass){
									console.log("登录成功")
									uni.switchTab({
										url:"/pages/index/index",
									})
									break;
							}else{
									uni.switchTab({
										url:"/pages/longin/longin",
									})
							}
						}
					}
				});
			},
		}
	}
</script>

<style>
	.userName {
		margin-left: 80px;
		margin-top: 40px;
	}

	.userPassword {
		margin-left: 80px;
		margin-top: 40px;
	}

	.hr-class {
		border-bottom: 1px solid #eaeaea;
		/* 分割线颜色 */
		margin: 20px;
		/* 上下边距 */
		margin-left: 0px;
		width: 300;
	}
</style>